package com.yuzhitong.shapi.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuzhitong.shapi.R;
import com.yuzhitong.shapi.base.BaseLayoutFragment;
import com.yuzhitong.shapi.base.Contents;
import com.yuzhitong.shapi.bean.MovieBean;

/**
 * Created by Brsya
 * CreateDate: 2022/5/28  14:27
 * Description:
 * 播放页面简介
 */
public class PlayInfoFragment extends BaseLayoutFragment {
    private LinearLayout llInfoTitle;
    private TextView tvMovieTitle;
    private TextView tvMovieDirector;
    private TextView tvMoviePerformer;
    private TextView tvMovieDate;
    private TextView tvMovieInfo;

    private MovieBean movieBean;

    private OnCloseListener onCloseListener;

    public static PlayInfoFragment newInstance(MovieBean movieBean, OnCloseListener onCloseListener) {

        Bundle args = new Bundle();
        args.putSerializable(Contents.INTENT_MOVIE_DETAIL, movieBean);

        PlayInfoFragment fragment = new PlayInfoFragment();
        fragment.onCloseListener = onCloseListener;
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initView() {
        setContentViewId(R.layout.fragment_play_info);
        llInfoTitle = findViewById(R.id.ll_info_title);
        tvMovieTitle = findViewById(R.id.tv_movie_title);
        tvMovieDirector = findViewById(R.id.tv_movie_director);
        tvMoviePerformer = findViewById(R.id.tv_movie_performer);
        tvMovieDate = findViewById(R.id.tv_movie_date);
        tvMovieInfo = findViewById(R.id.tv_movie_info);
    }

    @Override
    protected void initData() {
        if (getArguments() != null) {
            if (getArguments().getSerializable(Contents.INTENT_MOVIE_DETAIL) instanceof MovieBean) {
                movieBean = (MovieBean) getArguments().getSerializable(Contents.INTENT_MOVIE_DETAIL);
            }
        }

        llInfoTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCloseListener != null) {
                    onCloseListener.onClose();
                }
            }
        });

        if (movieBean == null) {
            return;
        }
        tvMovieTitle.setText(movieBean.getName());
        tvMovieDirector.setText(getResources().getString(R.string.play_movie_director, movieBean.getVideoDirector()));
        tvMoviePerformer.setText(getResources().getString(R.string.play_movie_performer, movieBean.getVideoPerformer()));
        tvMovieDate.setText(getResources().getString(R.string.play_movie_year, movieBean.getVideoYear()));

        tvMovieInfo.setText(movieBean.getVideoDescribe());
    }

    public interface OnCloseListener{
        void onClose();
    }
}
